package com.sjp.myspring.context.support;

import com.sjp.myspring.beans.factory.JPBeanFactory;
import com.sjp.myspring.context.JPApplicationContext;

public abstract class JPAbstractApplicationContext implements JPApplicationContext {

    public void refresh() {
        onRefresh();
    }

    protected void onRefresh() {
        // For subclasses: do nothing by default.
    }

    public abstract JPBeanFactory getBeanFactory();

    @Override
    public Object getBean(String beanName) throws Exception {
        return getBeanFactory().getBean(beanName);
    }

    @Override
    public Object getBean(Class<?> clazz) throws Exception {
        return getBeanFactory().getBean(clazz.getName());
    }

    @Override
    public String[] getBeanDefinitionNames() {
        return getBeanFactory().getBeanDefinitionNames();
    }

    @Override
    public int getBeanDefinitionCount() {
        return getBeanFactory().getBeanDefinitionCount();
    }

    @Override
    public String getId() {
        return "1";
    }

    @Override
    public String getApplicationName() {
        return "ApplicationName";
    }
}
